package com.stwyj.sbd.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@ConditionalOnProperty(prefix = "spring.scheduler", name = {"enable"}, havingValue = "true")
@ConditionalOnMissingBean({TaskScheduler.class})
@EnableScheduling
@Configuration
public class SchedulerConfig {
    @Value("${spring.scheduler.pool-size}")
    private int poolSize;

    public SchedulerConfig() {
    }

    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(this.poolSize);
        return scheduler;
    }
}
